using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace MomentumV2
{
    class mBackgroundScreen : mGameScreen
    {

        #region Instance Variables

        ContentManager m_Content;
        Texture2D m_BackgroundTexture;
        SpriteFont m_SpriteFont;

        #endregion

        #region Initialization

        /// <summary>
        /// Constructor.
        /// </summary>
        public mBackgroundScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }

        /// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            if (m_Content == null)
            {
                m_Content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            m_BackgroundTexture = m_Content.Load<Texture2D>("Interface/MenuBackground");
            m_SpriteFont = m_Content.Load<SpriteFont>("Interface/VersionMenuFont");
        }

        /// <summary>
        /// Unloads graphics content for this screen.
        /// </summary>
        public override void UnloadContent()
        {
            m_Content.Unload();
        }

        #endregion

        #region Upate

        /// <summary>
        /// Updates the background screen. Unlike most screens, this should not
        /// transition off even if it has been covered by another screen: it is
        /// supposed to be covered, after all! This overload forces the
        /// coveredByOtherScreen parameter to false in order to stop the base
        /// Update method wanting to transition off.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);
        }

        #endregion

        #region Draw

        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
            string message = "Version: " + MomentumV2.version;
            Vector2 messageSize = m_SpriteFont.MeasureString(message);
            byte fade = TransitionAlpha;

            spriteBatch.Begin(SpriteBlendMode.None);
            spriteBatch.Draw(m_BackgroundTexture, fullscreen, new Color(fade, fade, fade));
            spriteBatch.End();
            spriteBatch.Begin();
            spriteBatch.DrawString(m_SpriteFont, message, new Vector2(10, viewport.Height - messageSize.Y - 10), new Color(fade, fade, fade));
            spriteBatch.End();
        }

        #endregion

    }
}
